package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysFruits;
import com.ruoyi.system.service.ISysFruitsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 水果信息Controller
 * 
 * @author ruoyi
 * @date 2023-10-31
 */
@RestController
@RequestMapping("/system/fruits")
public class SysFruitsController extends BaseController
{
    @Autowired
    private ISysFruitsService sysFruitsService;

    /**
     * 查询水果信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:fruits:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFruits sysFruits)
    {
        startPage();
        List<SysFruits> list = sysFruitsService.selectSysFruitsList(sysFruits);
        return getDataTable(list);
    }

    /**
     * 导出水果信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:fruits:export')")
    @Log(title = "水果信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFruits sysFruits)
    {
        List<SysFruits> list = sysFruitsService.selectSysFruitsList(sysFruits);
        ExcelUtil<SysFruits> util = new ExcelUtil<SysFruits>(SysFruits.class);
        util.exportExcel(response, list, "水果信息数据");
    }

    /**
     * 获取水果信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fruits:query')")
    @GetMapping(value = "/{fruitId}")
    public AjaxResult getInfo(@PathVariable("fruitId") Long fruitId)
    {
        return success(sysFruitsService.selectSysFruitsByFruitId(fruitId));
    }

    /**
     * 新增水果信息
     */
    @PreAuthorize("@ss.hasPermi('system:fruits:add')")
    @Log(title = "水果信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFruits sysFruits)
    {
        return toAjax(sysFruitsService.insertSysFruits(sysFruits));
    }

    /**
     * 修改水果信息
     */
    @PreAuthorize("@ss.hasPermi('system:fruits:edit')")
    @Log(title = "水果信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFruits sysFruits)
    {
        return toAjax(sysFruitsService.updateSysFruits(sysFruits));
    }

    /**
     * 删除水果信息
     */
    @PreAuthorize("@ss.hasPermi('system:fruits:remove')")
    @Log(title = "水果信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fruitIds}")
    public AjaxResult remove(@PathVariable Long[] fruitIds)
    {
        return toAjax(sysFruitsService.deleteSysFruitsByFruitIds(fruitIds));
    }
}
